/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package koor.action.coursework;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import koor.action.Action;
import koor.action.ActionResult;
import koor.entity.CourseWork;
import koor.persistent.CourseWorkDAO;
import koor.service.ServiceLocator;

/**
 * The
 * <code>CourseWorkSearchAction</code> class represents action, used to search
 * courseWorks
 *
 * @author Admin
 */
public class CourseWorkSearchAction implements Action {

    @Override
    public String getName() {
        return "courseWork.search";
    }

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
        List<CourseWork> courseWorkList;
        try {
            courseWorkList = ServiceLocator.getService(CourseWorkDAO.class).findByName(request.getParameter("name"));
        } catch (RuntimeException e) {
            courseWorkList = new ArrayList<CourseWork>();
        }

        request.setAttribute("courseWorkList", courseWorkList);
        return ActionResult.forward("search/courseWorkSearch.jsp");
    }
}
